package com.vincent.javacourse.controller;


import com.vincent.javacourse.entity.Student;
import com.vincent.javacourse.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-12-24
 */
@RestController
@RequestMapping("//student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/list")
    private List<Student> list() {
        return this.studentService.list();
    }

    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Integer id) {
        return this.studentService.removeById(id);
    }

    @GetMapping("/find/{id}")
    public Student find(@PathVariable("id") Integer id) {
        return this.studentService.getById(id);
    }

    @PostMapping("/add")
    public boolean add(@RequestBody Student student) {
        return this.studentService.save(student);
    }

    @PutMapping("/update")
    public boolean update(@RequestBody Student student) {
        return this.studentService.updateById(student);
    }
}

